<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://unpkg.com/vue"></script>
    <script>
        window.onload=function() {
            var app4 = new Vue({
                el: '#app-4',
                methods: {
                    reverseMessage: function () {
                        this.message = this.message.split('').reverse().join('')
                    },
                    allremove:function(){
                        this.peoples=[]
                    },

                    addpeoples: function () {
                        this.peoples.push({name: this.username, age: this.age,time:new Date()})
                    }
                },

                data: {
                    parentMessage: 'Parent',
                    username:'',
                    age:null,
                    peoples: [
                        {name: 'lyy', age: 20,time:new Date()},
                        {name: 'nk', age: 20,time:new Date()}
                    ]
                },
                filters:{
                    hhmmss:function(val){
                        return(val.getHours()+":"+val.getMinutes()+":"+val.getSeconds())
                    },
                    capitalize: function (value) {
                        if (!value) return ''
                        value = value.toString()
                        return value.charAt(0).toUpperCase() + value.slice(1)
                    }
                }

            })
        }
    </script>
</head>
<body>
<div id="app-4">
    <p>{{ message }}</p>
    <p>用户名</p>
    <input v-model="username">
    <p>年龄</p>
    <input v-model="age">
    <button v-on:click="addpeoples">添加</button>
    <button v-on:click="allremove">全部删除</button>
    <table border="1">
        <tr>
         <th>序号</th><th>姓名</th><th>年龄</th><th>添加时间</th><th>操作</th>
        </tr>
        <tr v-for="(people, index) in peoples">
            <td>{{ index+1 }}</td>
            <td>{{people.name|capitalize}}</td>
            <td>{{people.age}}</td>
            <td>{{people.time|hhmmss}}</td>
            <td><button v-on:click="peoples.splice(index, 1)">删除</button></td>
        </tr>
    </table>
</div>
</body>
</html>